//
//  TestClass.m
//  TableViewTestDemo
//
//  Created by 张蒙召 on 2020/12/23.
//  Copyright © 2020 张蒙召. All rights reserved.
//

#import "TestClass.h"
#import "ClassA.h"
#import <objc/runtime.h>

@implementation TestClass

//动态方法解析

//+ (BOOL)resolveClassMethod:(SEL)sel {
//
//}
+ (BOOL)resolveInstanceMethod:(SEL)sel {
    if (sel == @selector(testMethod)) { // 这个判断是为了 选择针对那个方法做动态方法解析

        Method method = class_getInstanceMethod(NSClassFromString(@"ClassA"), @selector(method1));
        class_addMethod(self, sel, method_getImplementation(method), method_getTypeEncoding(method));
        // 代表有动态添加方法
        return YES;
    }
    return [super resolveInstanceMethod:sel];
}

// 快速转发

//- (id)forwardingTargetForSelector:(SEL)aSelector {
//
//    ClassA *obj = [[ClassA alloc] init];
//    if ([obj respondsToSelector:aSelector]) {
//        return obj;
//    }
//    return nil;
//}

//// 消息转发
//- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
//    
//    if([super respondsToSelector:aSelector]) {
//        return [super methodSignatureForSelector:aSelector];
//    } else {
//        return [cat methodSignatureForSelector:aSelector];
//    }
//}
//- (void)forwardInvocation:(NSInvocation *)anInvocation {
//   
//    
//    SEL sel = anInvocation.selector;
//    if ([super respondsToSelector:sel]) {
//        [super forwardInvocation:anInvocation];
//    }else {
//        [anInvocation invokeWithTarget:cat];
//    }
//    
//}

- (void)add {
    NSLog(@"add");
}
- (void)other {
    NSLog(@"other");
}
@end
